<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE>
<html>
  <head>    
  	<base href="<%=basePath%>">
    <title></title>   
	<link rel="stylesheet" type="text/css" href="/css/edittable.css"  ></link>  
	<link rel="stylesheet" type="text/css" href="/css/validate.css"  ></link>  

	<script type="text/javascript"  src="/js/jquery-1.8.0.js"></script>
	
	<script>
		var result1 = false;
		//表单校验
		$(function(){
			$("#cateName").blur(function(){
				var text = /^.{2,20}$/;
				var a=$("#cateName").val();
				if(text.test(a)){
					$.ajax({
						url:"GoodsServlet.do",
						type:"post",
						data:{cateName:a,flag:"checkParentName"},
						success:function(data){
							if(data==1){
								$("#cateName_msg").html("√");
								$("#cateName_msg").css("color","green");
								result1=true;
							}else{
								$("#cateName_msg").html("分类名称已存在");
								$("#cateName_msg").css("color","red");
								result1=false;
							}
						}
					})
				}else{
					$("#cateName_msg").html("输入错误，长度 2-20 位非空白字符");
					$("#cateName_msg").css("color","red");
					result1=false;
				}
			})
		})
		function validateInput(){
			if(result1){
				var l=confirm("确认添加吗");
				if(l){
					return true;
				}else{
					return false;
				}
			}else{
				alert("请按要求填写");
				return false;
			}
		}
	</script>
  </head>
  
  <body>
     <div class ="div_title">
		 <div class="div_titlename"><span>商品管理    添加一级分类</span></div>
	 </div>
				 
	 <form action="GoodsServlet.do?flag=addParent" method="post"  onsubmit="return validateInput()">
	 	<input type="hidden" name="flag" value="addbigcate" />
		 <table class="edit_table" >
		 		<tr>
		 			 	<td class="td_info">分类名称:</td>	
		 			 	<td class="td_input_short"> 
		 			 		<input type="text" class="txtbox" id="cateName" name="cateName" value="${param.cateName}"/> 
		 			 	</td>   
		 			 	<td>
		 			 		<label class="validate_info" id="cateName_msg">长度 2-20 位非空白字符</label>
		 			 	</td> 
		 		</tr>


		 		<tr>
		 			<td class="td_info">分类描述:</td>	
		 			<td><textarea rows="4" cols="27" name="des" class="txtarea">${param.des}</textarea> </td>	
		 			<td><label></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info"> </td>	
		 			<td> 
		 			<input class="form_btn" type="submit" value="提交" /> 
		 			<input type="reset"  class="form_btn"  value="重置" /> </td>	
		 			<td>
		 				<label id="result_msg" class="result_msg">${msg}</label>
		 			</td>	
		 		</tr>
		</table>
     </form>
  </body>
</html>
